Skip to content

Conversation

@9pace
Copy link
Contributor

@9pace 9pace commented Oct 20, 2025

Problem

When using imported Cognito resources in Amplify Gen2 with SSO enabled, login redirects were broken because the initializer Lambda unconditionally appended .auth.{region}.amazoncognito.com to the OAuth domain.
This caused malformed redirect URLs when a custom domain was already set in the Cognito User Pool (e.g., auth.dev.example.comauth.dev.example.com.auth.us-east-1.amazoncognito.com).

Issue number, if available: #2991

Changes

  • Updated getUserPoolOutputs logic so that:
    • If a custom domain is provided, it is used as-is.
    • Otherwise, fallback to Cognito-managed domain ({domain}.auth.{region}.amazoncognito.com).
  • Ensures fullDomainPath is properly constructed in both scenarios.
    This fixes the malformed OAuth redirect URLs when signing in via SSO providers (e.g., Google).

Validation

  • Manually tested with imported Cognito resources and a custom domain (auth.dev.example.com) → redirect now works correctly.
  • Verified fallback behavior with Cognito-managed domains continues to work.
  • Confirmed still detects Google as an IdP and completes the sign-in flow.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

sotolucas and others added 4 commits September 27, 2025 21:47
…uffix

Ensure fullDomainPath uses the custom domain as-is when provided,
falling back to the Cognito-managed domain construction only if
no custom domain exists. This resolves malformed OAuth redirect
URLs when using imported Cognito resources with SSO.
…th scenarios

- Add test for custom domain with external login providers
- Add test for cognito-managed domain with external login providers
- Verify oauthCognitoDomain is correctly set for both scenarios
@9pace 9pace requested a review from a team as a code owner October 20, 2025 20:28
@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2025

🦋 Changeset detected

Latest commit: 588096b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/backend-auth Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@ShadowCat567 ShadowCat567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good! Make sure to merge main into this branch to update it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you have another change set file, you should be able to remove this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ty!

@9pace 9pace merged commit a13d72d into main Oct 20, 2025
52 checks passed
@9pace 9pace deleted the fix/cognito-custom-domain-redirect branch October 20, 2025 21:13
osama-rizk pushed a commit that referenced this pull request Oct 28, 2025
…uffix (#3024)

<!--
Thank you for your Pull Request! Please describe the problem this PR
fixes and a summary of the changes made.
Link to any relevant issues, code snippets, or other PRs.

For trivial changes, this template can be ignored in favor of a short
description of the changes.
-->

## Problem
When using imported Cognito resources in Amplify Gen2 with SSO enabled,
login redirects were broken because the initializer Lambda
unconditionally appended `.auth.{region}.amazoncognito.com` to the OAuth
domain.
This caused malformed redirect URLs when a custom domain was already set
in the Cognito User Pool (e.g., `auth.dev.example.com` →
`auth.dev.example.com.auth.us-east-1.amazoncognito.com`).
<!--
Describe the issue this PR is solving
-->

**Issue number, if available:** #2991 

## Changes

<!--
Summarize the changes introduced in this PR. This is a good place to
call out critical or potentially problematic parts of the change.
-->

- Updated getUserPoolOutputs logic so that:
  - If a custom domain is provided, it is used as-is.
- Otherwise, fallback to Cognito-managed domain
({domain}.auth.{region}.amazoncognito.com).
- Ensures fullDomainPath is properly constructed in both scenarios.
This fixes the malformed OAuth redirect URLs when signing in via SSO
providers (e.g., Google).

## Validation

<!--
Describe how changes in this PR have been validated. This may include
added or updated unit, integration and/or E2E tests, test workflow runs,
or manual verification. If manual verification is the only way changes
in this PR have been validated, you will need to write some automated
tests before this PR is ready to merge.

For changes to test infra, or non-functional changes, tests are not
always required. Instead, you should call out _why_ you think tests are
not required here.

If changes affect a GitHub workflow that is not included in the PR
checks, include a link to a passing test run of the modified workflow.
--->

- Manually tested with imported Cognito resources and a custom domain
(auth.dev.example.com) → redirect now works correctly.
- Verified fallback behavior with Cognito-managed domains continues to
work.
- Confirmed <Authenticator> still detects Google as an IdP and completes
the sign-in flow.

## Checklist

<!--
These items must be completed before a PR is ready to be merged.
Feel free to publish a draft PR before these items are complete.
-->

- [ ] If this PR includes a functional change to the runtime behavior of
the code, I have added or updated automated test coverage for this
change.
- [ ] If this PR requires a change to the [Project Architecture
README](../PROJECT_ARCHITECTURE.md), I have included that update in this
PR.
- [ ] If this PR requires a docs update, I have linked to that docs PR
above.
- [ ] If this PR modifies E2E tests, makes changes to resource
provisioning, or makes SDK calls, I have run the PR checks with the
`run-e2e` label set.

_By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license._

---------

Co-authored-by: Lucas Leonardo Soto <[email protected]>
Co-authored-by: Lucas Leonardo Soto <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants